package user1;

import java.util.Scanner;

/**
 * Create by IntelliJ IDEA
 *
 * @author: jsonor
 * @date-Time: 2018/5/11 8:59
 * @description:
 */
public class UserTest {
  private static User1Dao dao = new User1IO();

  public static void main(String[] args) {
    while (true){
      System.out.println("----欢迎光临----");
      System.out.println("1.注册");
      System.out.println("2.登陆");
      System.out.println("3.查询所有用户");
      System.out.println("4.退出");
      System.out.println("请输入您的选择：");
      Scanner scanner=new Scanner(System.in);
      int num=scanner.nextInt();
      switch(num){
        case 1:
          registerFace();
          break;
        case 2:
          loginFace();
          break;
        case 3:
          queryALLface();
          break;
        case 4:
          System.out.println("欢迎下次光临");
          System.exit(0);
          break;
        default:
          System.out.println("输入有误");
          break;
      }
    }
  }

  private static void queryALLface() {
    System.out.println("-----查询用户所有界面-----");
    dao.quereyAll();
  }

  private static void loginFace() {
    System.out.println("----登陆界面----");
    Scanner sc=new Scanner(System.in);
    System.out.println("请输入用户名");
    java.lang.String name=sc.nextLine();
    System.out.println("请输入密码");
    java.lang.String password=sc.nextLine();

    boolean flag=dao.login(name,password);
    if(flag){
      System.out.println("登陆成功，可以玩小游戏了");
    }else {
      System.out.println("失败！用户名或密码错误！");
    }
  }

  private static void registerFace() {
    System.out.println("-----注册界面-----");
    Scanner sc=new Scanner(System.in);
    Scanner sc1=new Scanner(System.in);
    System.out.println("请输入学号");
    int id=sc.nextInt();
    System.out.println("请输入用户名");
    java.lang.String name=sc1.nextLine();
    System.out.println("请输入密码");
    java.lang.String password= sc1.nextLine();
    System.out.println("请输入年龄");
    java.lang.String age=sc.nextLine();

    user user=new user(id,name,password,age);

    dao.register(user);
    System.out.println("注册成功");

  }

}
